<%@ WebService Language="C#" class="SecurityWebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Collections.Generic;
using BLL;
// From Microsoft.Web.Extensions.dll assembly
//using System.Web.UI;
//using System.Web.Services.Protocols;

public struct SecurityInfo
{
	public string Code;
	public string CompanyName;
	public double Price;
}

[WebService(Namespace = "http://microsoft.com/webservices2/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[ScriptService]
public class SecurityWebService : WebService
{
	private SecurityInfo Security;
	
	public SecurityWebService()
	{
		Security.Code = "";
		Security.CompanyName = "";
		Security.Price = 0;
	}

	private void AssignValues(string Code)
	{
		// This is where you use your business components. 
		// Method calls on Business components are used to populate the data.
		// For demonstration purposes, I will add a string to the Code and
		//		use a random number generator to create the price feed.
					
		Security.Code = Code;
		Security.CompanyName = Code + " Pty Ltd";
		Random RandomNumber = new System.Random();
		Security.Price = double.Parse(new System.Random(RandomNumber.Next(1,10)).NextDouble().ToString("##.##"));
	}


    [WebMethod(Description="This method call will get the company name and the price for a given security code.",EnableSession=false)]
	public SecurityInfo GetSecurityInfo(string Code)
	{
		AssignValues(Code);
		SecurityInfo SecurityDetails = new SecurityInfo();
		SecurityDetails.Code = Security.Code;
		SecurityDetails.CompanyName = Security.CompanyName;
		SecurityDetails.Price = Security.Price;
		return 	SecurityDetails;
	}

    [WebMethod(Description = "This method call will get similar dishes with the given dish.", EnableSession = false)]
    public List<Entities.Dish> GetDishesWithSimilarName(string dishName)
    {
        List<Entities.Dish> dishes = Command.DishesWithSimilarName(dishName);
        return dishes;
    }

    [WebMethod(Description = "This method call is to comment.", EnableSession = false)]
    public bool Comment(Int16 scoreId, Int16 level, String content)
    {
        Command.CommentLevel commentLevel = (Command.CommentLevel)level;

        if (!Enum.IsDefined(typeof(Command.CommentLevel), commentLevel))
            return false;

        return Command.Comment(scoreId, commentLevel, content);
    }

    [WebMethod(Description = "This method call is to get comment summeries.", EnableSession = false)]
    public Entities.Score GetScore(Int16 scoreId)
    {
        return Command.GetScore(scoreId);
    }    

    [WebMethod(Description = "This method call is to test.", EnableSession = false)]
    public String SayHello(String name)
    {
        return "Hello world " + name + "!";
    }
}
